﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using PowerArrow.nasa.Model;
using SilverlightCairngorm.Control;
using PowerArrow.nasa.Control;
using PowerArrow.nasa.View;

namespace PowerArrow
{
    public partial class Page : UserControl
    {
        public Page()
        {
            InitializeComponent();

            PowerArrowController controller = PowerArrowController.Instance;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            this.DataContext = PowerArrowModel.Instance;
        }

        private void Run_Click(object sender, RoutedEventArgs e)
        {
            CairngormEvent cgEvt = new CairngormEvent(PowerArrowController.SC_EVENT_RUN_BG);
            cgEvt.dispatch();
        }


        private void OnReady()
        {
            if (!PowerArrowModel.Instance.IsFlying)
            {
                PowerArrowModel.Instance.IsFlying = true;
                CairngormEvent stopBgEvt = new CairngormEvent(PowerArrowController.SC_EVENT_STOP_BG);
                stopBgEvt.dispatch();
                CairngormEvent runBgEvt = new CairngormEvent(PowerArrowController.SC_EVENT_RUN_BG);
                runBgEvt.dispatch();
                CairngormEvent onReadyEvt = new CairngormEvent(PowerArrowController.ARR_EVENT_ONREADY);
                onReadyEvt.dispatch();
            }
        }

        private void OnFire()
        {
            CairngormEvent cgEvt = new CairngormEvent(PowerArrowController.ARR_EVENT_ONFIRE);
            cgEvt.dispatch();
        }

        private void xControl_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            this.OnReady();
        }

        private void xControl_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            this.OnFire();
        }
    }
}
